﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using System.Runtime.Serialization;

namespace CMD.BAL.CAT
{
   [DataContractAttribute]
   public class Zona
   {
       [DataMemberAttribute(EmitDefaultValue = false)]
       public int idZona;
       [DataMemberAttribute(EmitDefaultValue = false)]
       public string dscZona;
       public static DataTable GetData()
       {
            DataTable dt;
            //ejecutar store
            dt = CMD_WEB.DAL.SrvDB.ExecuteQuery("exec SP_CMD_CAT_SEL_ZONA");
            return dt;
       }
       public static DataTable GetDataId(int idClo)
       {
           DataTable dt;
           //ejecutar store
           dt = CMD_WEB.DAL.SrvDB.ExecuteQuery("exec SP_CMD_CAT_SEL_ZONE'" + idClo + "'");
           return dt;
       }
       public static List<Zona> GetDataZona()
       {
           try
           {
               DataTable dt;
               dt = Zona.GetData();
               if (dt.Rows.Count == 0)
               {
                   return null;
               }
               else
               {
                   List<Zona> list = dt.AsEnumerable().Select(
                   row => new Zona
                   {
                       idZona = row.Field<int?>("ID_ZONA").GetValueOrDefault(),
                       dscZona = String.IsNullOrEmpty(row.Field<string>("DSC_ZONA"))
                       ? ""
                       : row.Field<string>("DSC_ZONA"),
                   }
                   ).ToList();
                   return list;
               }
           }
           catch (Exception ex)
           {

               throw ex;
           }
       }
       public static List<Zona> GetDataIdZone(int idClo)
       {
           try
           {
               DataTable dt;
               dt = Zona.GetDataId(idClo);
               if (dt.Rows.Count == 0)
               {
                   return null;
               }
               else
               {
                   List<Zona> list = dt.AsEnumerable().Select(
                   row => new Zona
                   {
                       idZona = row.Field<int?>("ID_ZONA").GetValueOrDefault(),
                       dscZona = String.IsNullOrEmpty(row.Field<string>("DSC_ZONA"))
                       ? ""
                       : row.Field<string>("DSC_ZONA"),
                   }
                   ).ToList();
                   return list;
               }
           }
           catch (Exception ex)
           {

               throw ex;
           }
       }

       public Zona() 
       {
           idZona = 0;
           dscZona = "";
       }
       //public Zona(string dscZona)
       public Zona(int idZona, string dscZona) 
       {
           this.idZona = idZona;
           this.dscZona = dscZona;
       }
   }
}
